package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.happy.cat.common.utils.SecurityUtils;
import com.happy.cat.common.utils.StringUtils;
import com.happy.cat.common.utils.poi.ExcelUtil;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.framework.web.page.TableDataInfo;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import com.happy.cat.project.system.domain.CatChatroomType;
import com.happy.cat.project.system.service.ICatChatroomTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 聊天厅室类型Controller
 *
 * @author verne
 * @date 2020-07-18
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/chatroomType" )
@Api("聊天厅室类型 API")
public class CatChatroomTypeController extends BaseController {

    private final ICatChatroomTypeService iCatChatroomTypeService;

    /**
     * 查询聊天厅室类型列表
     */
    @ApiOperation(value = "查询聊天厅室类型列表",notes = "查询聊天厅室类型列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:chatroomType:list')")
    @GetMapping("/list")
    public TableDataInfo list(CatChatroomType catChatroomType)
    {
        startPage();
        LambdaQueryWrapper<CatChatroomType> lqw = new LambdaQueryWrapper<CatChatroomType>();
        if (StringUtils.isNotBlank(catChatroomType.getTypeName())){
            lqw.like(CatChatroomType::getTypeName ,catChatroomType.getTypeName());
        }
        if (catChatroomType.getChatroomType() != null){
            lqw.eq(CatChatroomType::getChatroomType ,catChatroomType.getChatroomType());
        }
        if (catChatroomType.getWheat() != null){
            lqw.eq(CatChatroomType::getWheat ,catChatroomType.getWheat());
        }
        if (catChatroomType.getCreateDate() != null){
            lqw.eq(CatChatroomType::getCreateDate ,catChatroomType.getCreateDate());
        }
        if (catChatroomType.getStatus() != null){
            lqw.eq(CatChatroomType::getStatus ,catChatroomType.getStatus());
        }
        List<CatChatroomType> list = iCatChatroomTypeService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出聊天厅室类型列表
     */
    @ApiOperation(value = "导出聊天厅室类型列表",notes = "导出聊天厅室类型列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:chatroomType:export')" )
    @Log(title = "聊天厅室类型" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(CatChatroomType catChatroomType) {
        LambdaQueryWrapper<CatChatroomType> lqw = new LambdaQueryWrapper<CatChatroomType>(catChatroomType);
        List<CatChatroomType> list = iCatChatroomTypeService.list(lqw);
        ExcelUtil<CatChatroomType> util = new ExcelUtil<CatChatroomType>(CatChatroomType. class);
        return util.exportExcel(list, "chatroomType" );
    }

    /**
     * 获取聊天厅室类型详细信息
     */
    @ApiOperation(value = "获取聊天厅室类型详细信息",notes = "获取聊天厅室类型详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:chatroomType:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iCatChatroomTypeService.getById(id));
    }

    /**
     * 新增聊天厅室类型
     */
    @ApiOperation(value = "新增聊天厅室类型",notes = "新增聊天厅室类型",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:chatroomType:add')" )
    @Log(title = "聊天厅室类型" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CatChatroomType catChatroomType) {
        catChatroomType.setCreateDate(new Date());
        catChatroomType.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iCatChatroomTypeService.save(catChatroomType) ? 1 : 0);
    }

    /**
     * 修改聊天厅室类型
     */
    @ApiOperation(value = "修改聊天厅室类型",notes = "修改聊天厅室类型",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:chatroomType:edit')" )
    @Log(title = "聊天厅室类型" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CatChatroomType catChatroomType) {
        catChatroomType.setCreateDate(new Date());
        catChatroomType.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iCatChatroomTypeService.updateById(catChatroomType) ? 1 : 0);
    }

    /**
     * 删除聊天厅室类型
     */
    @ApiOperation(value = "删除聊天厅室类型",notes = "删除聊天厅室类型",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:chatroomType:remove')" )
    @Log(title = "聊天厅室类型" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iCatChatroomTypeService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
